﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TTTTBHYT.BUS;
using TTTTBHYT.VO;

namespace TTTTBHYT
{
    public partial class frmBV : frmParent 
    {
        public string Mabv="56";
        public string Tenbv;
        private Mau29BUS Mau29BUS;
        public frmBV()
        {
            InitializeComponent();
        }

        private void frmBV_Load(object sender, EventArgs e)
        {
             Mau29BUS = new Mau29BUS();
             GetValueToControl();
            
        }
        private void GetValueToControl()
        {
            string condition = Getconditon();
            flxBV.Rows.Count = 1;
            if (condition == "") { return; }
            DataTable dbBV = Mau29BUS.GetListBV(condition);
            int i = 1;
            foreach (DataRow drBV in dbBV.Rows)
            {

                flxBV.Rows.Count = flxBV.Rows.Count + 1;
                flxBV.Rows[i]["STT"] = i;
                flxBV.Rows[i]["MABV"] = drBV["MA_BV"];
                flxBV.Rows[i]["TENBV"] = drBV["TEN_BV"].ToString();
                flxBV.Rows[i]["MATINH"] = drBV["MA_TINH"];
                flxBV.Rows[i]["TenTinh"] =drBV["Ten_Tinh"].ToString();
                i++;
            }
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            string condition = Getconditon();
            flxBV.Rows.Count = 1;
            if (condition == "") { return; }
            DataTable dbBV = Mau29BUS.GetListBV(condition);
            int i = 1;
            
            foreach (DataRow drBV in dbBV.Rows)
            {
                flxBV.Rows.Count = flxBV.Rows.Count + 1;
                flxBV.Rows[i]["STT"] = i;
                flxBV.Rows[i]["MABV"] = drBV["MA_BV"];
                flxBV.Rows[i]["TENBV"] = drBV["TEN_BV"].ToString();
                flxBV.Rows[i]["MATINH"] = drBV["MA_TINH"];
                flxBV.Rows[i]["TenTinh"] = drBV["Ten_Tinh"].ToString(); ;
                i++;
            }
        }
        private string Getconditon()
        {
            string condition = "";
            if (txtMatinh.Text != "")
            {
                condition = condition + " and Dmbv.MA_TINH = N'" + txtMatinh.Text + "'";
            }
            if (txtTentinh.Text.Trim() != "")
            {
                condition = condition + " and b.Ten_Tinh like N'%" + txtTentinh.Text + "%'";
            }
            if (txtMabv.Text.Trim() != "")
            {
                condition = condition + " and Dmbv.MA_BV = N'" + txtMabv.Text + "'";
            }
            if (txtTenBV.Text.Trim() != "")
            {
                condition = condition + " and Dmbv.TEN_BV like N'%" + txtTenBV.Text + "%'";
            }
            return condition;
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void flxBV_DoubleClick(object sender, EventArgs e)
        {           
            if (flxBV.Selection.TopRow  >= 1)
            {
                 Mabv = flxBV.Rows[flxBV.Selection.TopRow]["MATINH"].ToString().Trim() + flxBV.Rows[flxBV.Selection.TopRow]["MABV"].ToString();
                 Tenbv = flxBV.Rows[flxBV.Selection.TopRow]["TENBV"].ToString();
            }
            this.Close();
        }

    }
}
